package com.i2works.smartluolong.api.controller.app;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.i2works.smartluolong.api.utils.BaseModule;
import com.i2works.smartluolong.utils.entity.R;
import com.i2works.smartluolong.utils.entity.Result;
import com.i2works.smartluolong.utils.exception.ServiceException;
import com.i2works.smartluolong.web.entity.app.AppVersionDO;
import com.i2works.smartluolong.web.entity.app.AppVersionQuery;
import com.i2works.smartluolong.web.service.app.IAppVersionService;

@Controller
@RequestMapping("/appVersion")
public class AppVersionController extends  BaseModule{ 

	private final IAppVersionService appVersionService;
	
	public AppVersionController(IAppVersionService appVersionService) {
		this.appVersionService=appVersionService;
	}
		
    /**
     * app版本控制接口
     * */
	@PostMapping(value= {"","/"})
	@ResponseBody
	public Result index(String versionNo) {

		try {
			  AppVersionQuery query=new AppVersionQuery();
			  List<AppVersionDO> list=	appVersionService.queryList(query);
			  AppVersionDO  appVersion=list.get(0);
			  if(versionNo!=null) {
			  if(!versionNo.equals(appVersion.getVersionNo())) {
				  appVersion.setIsUpdate(1);
			  }
		  }
			return  R.success(appVersion);
		} catch (ServiceException e) {
			e.printStackTrace();
			return  R.error();
		}

	}


	
}
